<!--
 * @Author: 刘晟勇
 * @Date: 2021-10-19 19:37:16
 * @LastEditTime: 2021-10-23 13:54:27
 * @Description: 账号管理界面
-->

<template>
  <div class="profile">
    <!-- 头部区域 -->
    <HeaderNav>
      <template #icon>
        <i class="iconfont icon-left" @click="goback"></i>
      </template>
      <template #center>
        <span>账号管理</span>
      </template>
    </HeaderNav>
    <section class="profile-content">
      <h3 class="profile-title">当前登录账号</h3>
      <div class="profile-item info">
        <img src="@/assets/user.png" />
        <div>
          <span class="username">{{ userInfo.username }}</span>
          <span class="email">邮箱：{{ userInfo.email }}</span>
        </div>
      </div>
      <router-link tag="div" to="/" class="profile-item">
        <span>修改登录密码</span>
        <i class="iconfont icon-right"></i>
      </router-link>
      <router-link tag="div" to="/" class="profile-item">
        <span>修改个人信息</span>
        <i class="iconfont icon-right"></i>
      </router-link>
      <router-link tag="div" to="/" class="profile-item">
        <span>收货地址管理</span>
        <i class="iconfont icon-right"></i>
      </router-link>
    </section>
    <section class="profile-footer">
      <div class="footer-con">
        <div>
          <i class="iconfont icon-yijian"></i>
          <span>意见反馈</span>
        </div>
        <div class="client">
          <i>ZXG</i>
          <span>客户端</span>
        </div>
        <div class="logout" @click="userLogout">
          <i class="iconfont icon-40one"></i>
          <span>退出登录</span>
        </div>
      </div>
      <p class="zxg">知心购</p>
    </section>
  </div>
</template>

<script>
// 公共组件的引用
import HeaderNav from "@/components/header-nav.vue";

// 导入混入api方法
import { loginOutApi } from "@/api/login";

import { mapState } from "vuex";

export default {
  name: "Profile",
  components: {
    HeaderNav,
  },
  computed: {
    ...mapState(["userInfo"]),
  },
  methods: {
    goback() {
      this.$router.go(-1);
    },
    userLogout() {
      loginOutApi((data) => {
        if (data.status === 0) {
          sessionStorage.token = ""
          sessionStorage.isLogin = false
          this.$store.commit("setLoginStatue", {token: null, isLogin: false})
          this.$router.replace("/")
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.profile {
  .profile-content {
    width: 100%;

    .profile-title {
      width: 100%;
      padding: 30px;
      @include boxSizing;
      font-weight: normal;
      color: #999;
      border-bottom: 1px solid #f7f7f7;
    }

    .profile-item {
      @extend .profile-title;
      @include fj;
      color: #999;
      font-size: 30px;

      &.info {
        justify-content: left;

        img {
          width: 100px;
          height: 100px;
          @include borderRadius(50%);
        }

        div {
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          padding-left: 30px;
          font-size: 30px;
          color: #666;

          span:last-child {
            color: #999;
          }
        }
      }

      .iconfont {
        font-size: 38px;
      }
    }
  }

  .profile-footer {
    width: 100%;
    margin-top: 200px;

    .footer-con {
      display: flex;
      width: 100%;

      div {
        flex: 1;
        height: 40px;
        text-align: center;
        line-height: 34px;
        font-size: 26px;
        color: #333;

        &.client {
          line-height: 50px;
        }

        &.logout {
          line-height: 44px;
        }

        i {
          font-style: normal;
          font-size: 30px;
          color: #999;

          &.iconfont {
            font-size: 44px;
          }
        }
      }
    }

    .zxg {
      width: 100%;
      margin-top: 140px;
      text-align: center;
      font-size: 50px;
      color: $red;
    }
  }
}
</style>
